<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use app\models\Supplier;

$this->title = Yii::t('app', 'Cruises');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="cruise-index">

    <h2 class="page-header"><?= Html::encode($this->title) ?>
    <p class="pull-right"><?= Html::a(Yii::t('app', 'Create Cruise'), ['create'], ['class' => 'btn btn-success']) ?></p>
    </h2>

<?PHP Pjax::begin(['id'=>'cruise', 'timeout'=>3000, 'linkSelector'=>'#cruise a[data-sort], #cruise a[data-page]']);?>
    <p><?php  echo $this->render('_search', ['model' => $searchModel]); ?></p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'layout'  =>  "{items}\n{pager}",
        'columns' => [
         //   ['class' => 'yii\grid\SerialColumn'],
            'supplier.company',
             [
                 'attribute' => 'name',
                 'value' => function ($model) {
                        $url =  sprintf("/front/default/cruise?id=%d", $model->id);
                        return Html::a($model->name, $url, ['title' =>$model->name, 'target'=>'_blank']);
                     },
                 'format'=> 'raw',   
             ],
            'en_name',
            'code',
            [
                'attribute' => 'from_city',
                'filter' =>  Yii::$app->params['city'],
                'value' => function ($model) {
                    $city = Yii::$app->params['city'];
                    return isset($city[$model->from_city]) ? $city[$model->from_city]:'' ;
                    },
                'format' => 'raw',
            ],
            [
                'attribute' => 'to_city',
                'filter' =>  Yii::$app->params['city'],
                'value' => function ($model) {
                    $city = Yii::$app->params['city'];
                    return isset($city[$model->to_city]) ? $city[$model->to_city] : '';
                    },
                'format' => 'raw',
            ],
            //'created_at:date',
            //'updated_at:relativeTime',
            [
                'label'=>'图片',
                'format'=>'raw',
                'value' => function($model){
                    $r =  urlencode(\yii::$app->request->getUrl());
                    $url = sprintf("/cruise/cruise/deck?id=%d", $model->id);
                    $url2 = sprintf("/cruise/cruise/image?id=%d", $model->id);
                    $url3 = sprintf("/product/template/index?cruise_id=%d", $model->id);
                    $str =  
                           Html::a('<i class="fa fa-th-list"></i>',$url,['title' => '甲板', 'target'=>'_blank'])."&nbsp;&nbsp;". 
                           Html::a('<i class="fa fa-image"></i>',$url2,['title' => '图片', 'target'=>'_blank'])."&nbsp;&nbsp;".
                           Html::a('<i class="fa fa-sticky-note-o"></i>',$url3,['title' => '模板', 'target'=>'_blank']);
                    return $str;
                }
            ],
            [
                'label'=>'其它信息',
                'format'=>'raw',
                'value' => function($model){
                    $r =  urlencode(\yii::$app->request->getUrl());

                    $url = sprintf("/cruise/room/index?cruise_id=%d", $model->id);
                    $url2 = sprintf("/cruise/restaurant/index?cruise_id=%d", $model->id);
                    $url3 = sprintf("/cruise/recreation/index?cruise_id=%d", $model->id);
                    $url4 = sprintf("/cruise/service/index?cruise_id=%d", $model->id);
                    //$url5 = sprintf("/cruise/cruise/image?id=%d", $model->id);

                    $str =  
                           Html::a('<i class="fa fa-hotel"></i>',$url,['title' => '舱房', 'target'=>'_blank'])."&nbsp;&nbsp;". 
                           Html::a('<i class="fa fa-cutlery"></i>',$url2,['title' => '餐饮', 'target'=>'_blank'])."&nbsp;&nbsp;".
                           Html::a('<i class="fa fa-microphone"></i>',$url3,['title'=>'娱乐','target'=>'_blank'])."&nbsp;&nbsp;".
                           Html::a('<i class="fa fa-server"></i>',$url4, ['title' => '服务', 'target'=>'_blank']);
                           //Html::a('<i class="fa fa-image"></i>',$url5,['title' => '图片', 'target'=>'_blank']);
                    return $str;
                }
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操 作',
                'template' =>"{view} {update}"
            ],
        ],
    ]); ?>
<?php Pjax::end(); ?></div>
